﻿@using ZDSoft.LMS.Web.Apps
@model ZDSoft.LMS.Web.Apps.PageList<ZDSoft.LMS.Domain.Role>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/Style/ViewPage.css")" rel="stylesheet" type="text/css" />
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%; background-color: White;"
    align="center">
    <tr>
        <td class="mbg">
            <table cellspacing="0" cellpadding="0" width="100%" border="0" valign="top">
                <tr>
                    <td>
                        <table style="height: 23px;" cellspacing="0" cellpadding="0" width="120" background="@Url.Content("~/Content/Images/m_17.gif")"
                            border="0">
                            <tr>
                                <td>
                                    <span class="contentPageTitle">&nbsp;&gt;&gt; 角色列表</span>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="titleContentDivider" height="6">
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<p>
    @Html.ActionLink("创建", "Create")
</p>
<table cellpadding="0" cellspacing="0" class="dataGrid">
    <tr>
        <th>
            名称
        </th>
        <th>
            状态
        </th>
        <th>
            用户
        </th>
        <th>
            操作
        </th>
    </tr>
    @if (Model == null || Model.Count() == 0)
    { 
        <td colspan="4">没有满足条件的数据！</td>
    }
    else
    {
    foreach (var item in Model)
    {
        <tr>
            <td>
                @item.RoleName
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IsActive)
            </td>
            <td>
                @if (item.Users == null || item.Users.Count == 0)
                { 
                    <span>没有配置</span>
                }
                else
                {
                    var allowToDisplay = 3;
                    var roleCount = item.Users.Count;
                    for (int i = 0; i < item.Users.Count; i++)
                    {
                        var user = item.Users[i];
                    @Html.ActionLink(user.UserName, "Details/" + user.ID, "User");
                     if (roleCount != (i + 1))
                     {
                           if (allowToDisplay == (i + 1))
                           { 
                    <span>...@roleCount</span>
                           break;
                           }                     
                    <span>,</span>   
                    }
                   }
                }
            </td>
            <td>
                @Html.ActionLink("修改", "Edit", new { id = item.ID }) |
                @Html.ActionLink("详细信息", "Details", new { id = item.ID }) |
                @if (item.IsActive)
                {
                    @Html.ActionLink("注销", "SwitchStatus", new { id = item.ID }, new { onclick = "return confirm('真的打算注销吗?')" });
                }
                else
                {
                    @Html.ActionLink("激活", "SwitchStatus", new { id = item.ID }, new { onclick = "return confirm('真的打算激活吗?')" });
                }
                |
                @Html.ActionLink("配置权限", "Index", "Authorize", new { roleID = item.ID }, new { })
            </td>
        </tr>
    }
    }
</table>
